var logUtils = require("../log/logUtils");
var gUtils = require("../g/gUtils");
var deviceUtils = require("../device/deviceUtils");
var clickUtils = require("../click/clickUtils");
var swipeUtils = require("../swipe/swipeUtils");
var activityMap = require("./activityMap");
var pointMap = {
  关闭所有应用: [[420, 2006, 660, 2246], 1080, 2340],
};
module.exports = {
  appName: null,
  openApp(appName) {
    var activity = activityMap[appName];
    if (activity) {
      shizuku("am start " + activity);
      return;
    }
    this.appName = appName;
    var result = app.launchApp(appName);
    logUtils.log(appName.length);
    logUtils.log("打开：", appName, result ? "成功" : "失败");
    sleep(2 * 1000);
    return result;
  },
  closeRecent() {
    deviceUtils.home();
    sleep(2 * 1000);
    deviceUtils.recents();
    sleep(2 * 1000);
    if (["cannon", "evergo"].includes(device.product)) {
      swipeUtils.swipe(
        device.width / 4 + device.width / 8 + device.width / 16,
        device.height / 2,
        device.width / 20,
        device.height / 2,
        200
      );
    } else {
      swipeUtils.swipe(
        device.width / 2,
        device.height / 2,
        device.width / 2,
        device.height / 16,
        gUtils.random(300, 500)
      );
    }
    sleep(2 * 1000);
    deviceUtils.home();
    sleep(2 * 1000);
  },
  closeAll() {
    deviceUtils.home();
    sleep(2 * 1000);
    deviceUtils.recents();
    sleep(2 * 1000);
    clickUtils.clickPointMap(pointMap.关闭所有应用);
    sleep(2 * 1000);
  },
  checkInstall(appName) {
    return !!app.getPackageName(appName);
  },
};
